#include <gtest/gtest.h>
#include "task/task_controller.h"
#include "../sample/navigation_task.h"
#include "../sample/battery_level_check.h"
#include "scheduler/scheduler_factory.h"
#include "exclude/exclude_policy_factory.h"
#include "exclude/same_name_task_chain_exclude_policy.h"
#include "../sample/screen_return_zero_task.h"
#include "../sample/screen_return_zero_check.h"
#include "task/task_chain_factory.h"
#include "exclude_policy/policy_1.h"

TEST(test_task_controller_exclude_policy, test_task_controller_thread)
{
    task::TaskController taskController;
    taskController.setMaxParallelTaskCount(2);
    auto exclude_policy = exclude::ExcludePolicyFactory<exclude::SameNameTaskChainExcludePolicy>::createExcludePolicy(&taskController);
    taskController.appendStartExcludePolicy(exclude_policy);

    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");
    auto battery_check = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check");

    auto sequence_scheduler = scheduler::SchedulerFactory<scheduler::SequenceScheduler>::createScheduler("navigation_scheduler");

    sequence_scheduler->appendTask(battery_check);
    sequence_scheduler->appendTask(navigation_task);

    auto task_chain = new task::TaskChain("test_task_chain", sequence_scheduler);
    auto task_chain2 = new task::TaskChain("test_task_chain", sequence_scheduler);

    taskController.startTaskChain(task_chain);
    taskController.startTaskChain(task_chain2);

    while (true)
    {

    }

}

TEST(test_task_controller, test_task_controller_thread)
{
    task::TaskController taskController;
    taskController.setMaxParallelTaskCount(2);

    auto battery_level_check = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check");
    auto screen_return_zero_task = task::TaskFactory<ScreenReturnZeroTask>::createTask("screen_return_zero_task");
    auto screen_return_zero_check = task::TaskFactory<ScreenReturnZeroCheck>::createTask("screen_return_zero_check");
    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");

    auto screen_return_scheduler = scheduler::SchedulerFactory<scheduler::FallbackScheduler>::createScheduler("screen_return_scheduler");
    {
        screen_return_scheduler->appendTask(screen_return_zero_check);
        screen_return_scheduler->appendTask(screen_return_zero_task);
    }

    auto time_recharge_scheduler = scheduler::SchedulerFactory<scheduler::SequenceScheduler>::createScheduler("time_recharge_scheduler");
    time_recharge_scheduler->appendScheduler(screen_return_scheduler);
    time_recharge_scheduler->appendTask(battery_level_check);
    time_recharge_scheduler->appendTask(navigation_task);

    auto task_chain = task::TaskChainFactory::createTaskChain("test", time_recharge_scheduler);
    taskController.startTaskChain(task_chain);

    while (true)
    {

    }

    EASE_INFO("done");
}
